package com.benefm.multipar.pad.view;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.benefm.multipar.pad.R;

/**
 * Created by Administrator on 2017/8/9 0009.
 */

public class LoadingDialog extends Dialog {

    private Activity activity;
    private LayoutInflater inflater;

    public LoadingDialog(Activity activity) {
        super(activity, R.style.loadingDialog);
        this.activity = activity;
        inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        initView();
    }

    private void initView() {
        //设置不可取消，点击其他区域不能取消，实际中可以抽出去封装供外包设置
        View view = inflater.inflate(R.layout.dialog_loading, null);
        this.addContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        setCancelable(false);
    }

    public void showDialog(boolean b) {
        setCancelable(b);
        setCanceledOnTouchOutside(b);
        if (!activity.isDestroyed())
            show();
    }

}
